package com.masita.ventanas;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

public class BarraProgreso extends JFrame {

	JProgressBar barra = null;
	
	public BarraProgreso(String titulo, int longitud){
		super(titulo);
		init(titulo,longitud);
	}
	
	private void init(String titulo, int longitud){
		this.setUndecorated(true);
		
		JPanel panel = new JPanel();
		this.getContentPane().add(panel);
		panel.setLayout(null);
		panel.setBorder(BorderFactory.createRaisedBevelBorder());
		
		JLabel et = new JLabel("Actualizando ..");
		panel.add(et);
		et.setBounds(50,15,200,15);
		
		barra = new JProgressBar(0,longitud);
		barra.setStringPainted(true);
		panel.add(barra);
		barra.setBounds(50,30,200,20);
		this.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.WAIT_CURSOR));
	}
	
	public void setProgreso(int pos){
		barra.setValue(pos);
		if( pos == barra.getMaximum() )
			this.dispose();
	}
	
	public void mostrar(){
		this.setSize(new java.awt.Dimension(300,60));
		this.setResizable(false);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
	}
	
}
